package com.engr.lyx.blog.biz.controller;

import com.engr.lyx.blog.biz.service.PublicService;
import com.engr.lyx.blog.client.entity.Author;
import com.engr.lyx.common.annotation.FreeAccess;
import com.engr.lyx.common.base.ResultBody;
import com.engr.lyx.common.security.UserHelper;
import com.engr.lyx.common.security.UserProfileDetails;
import com.engr.lyx.common.utils.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: blog
 * @description: 公共模块
 * @author: lyx
 * @create: 2019-06-29
 **/
@Api(tags = "public resource")
@RestController
@RequestMapping(value = "/api/public", name = "public resource")
public class PublicController {

    @Autowired
    private PublicService publicService;

    @FreeAccess
    @GetMapping(value = "/author/info")
    @ApiOperation(value = "查找作者信息",notes = "查找作者信息")
    public ResultBody<Author> findAuthorInfoById(){

        UserProfileDetails userProfileDetails = UserHelper.getUserAuth();
        return ResultUtils.success(publicService.selectByUserId(userProfileDetails == null ? 1L : userProfileDetails.getUserId()));
    }

}
